package com.etop.jansing.entities;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by jansing on 2015/10/25.
 */
@Entity
@Table(name = "user")
public class User extends BaseEntity {
    @Column(name = "username")
    private String username;
    @Column(name = "password")
    private String password;
    @OneToMany(targetEntity = Role.class, fetch = FetchType.LAZY)
    @Fetch(FetchMode.SUBSELECT)
    @JoinTable(name = "userrole", joinColumns = {@JoinColumn(name = "uid")}
            , inverseJoinColumns = {@JoinColumn(name = "rid")})
    //JoinTable表示建立User-Role的中间表，名为userrole，自身在表的字段为uid，对方在表的字段为rid
//    @Transient
    private List<Role> roleList = new ArrayList<>();

    public User() {
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public List<Role> getRoleList() {
        return roleList;
    }

    public void setRoleList(List<Role> roleList) {
        this.roleList = roleList;
    }
}
